04. SQLAlchemy Object Lifecycle — Part 2
SQLAlchemy Object Lifecycle - Part 2 Heading
SQLAlchemy Object Lifecycle — Part 2
ND004 C01 L04 04 SQLAlchemy Object Lifecycle - Part 2
SQLAlchemy Object Lifecycle - Part 2 Recap
Takeaways
- A flush takes pending changes, and translates them into commands ready to be committed. It occurs:
-
when you call
Query
. Or -
on
db.session.commit()
A commit leads to persisted changes on the database + lets the db.session start with a new transaction.
When a statement has been flushed already, SQLAlchemy knows not to do the work again of translating actions to SQL statements.
SQLAlchemy Object Lifecycle - Part 2 Quiz
SOLUTION:
TrueFlush Quiz
SOLUTION:
- `Person.query.all()`
- `db.session.commit()`
- `Person.query.filter_by(name='Bob')`
- `Person.query.first().delete()`